package com.roc.web.action.estrn;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.constant.Role;
/**
 * haha
 * @author 160711BB
 *
 */
public class DayStasticsSearchCondition extends BaseSearchCondition{
	
	private static final long serialVersionUID = 1L;

	private String merNo;
	
	private String merName;
	
	private String minDate;
	
	private String maxDate;
	
	private String agentId;
	
	private String roleType;

	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();

		//商户号
		if (Constance.isNotEmpty(merNo)) {
			filedBeanList.add(new WhereHQLFieldBean("e.mcht_cd", merNo.trim(), "=", false));
		}
		if (Constance.isNotEmpty(merName)) {
			filedBeanList.add(new WhereHQLFieldBean("e.name_busi", merName.trim(),"LIKE", false, "ALL"));
		}
		
		
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		String countSql="";
		if (roleType.equals(Role.O_MANAGER.getCode() )) {
			countSql = "select count(1) from (select a.mcht_cd,a.term_id,sum(a.trans_count) transCount,sum(a.trans_amt) transAmt, "
	                +"sum(a.trans_fee) transFee,sum(a.income) income "
	                +"from t_report_day a,tbl_mer_agent_relation tm where a.mcht_cd=tm.merno and tm.agentid="+agentId+" and  a.trans_dt >= '"+minDate+"' and a.trans_dt <= '"+maxDate+"' "
	                +"group by a.mcht_cd, a.term_id) c, tbl_mcht_inf e,t_operators f where c.mcht_cd = e.mcht_cd "
	                +"and to_number(e.ext1) = f.id ";
		}else{
			countSql = "select count(1) from (select a.mcht_cd,a.term_id,sum(a.trans_count) transCount,sum(a.trans_amt) transAmt, "
	                +"sum(a.trans_fee) transFee,sum(a.income) income "
	                +"from t_report_day a where a.trans_dt >= '"+minDate+"' and a.trans_dt <= '"+maxDate+"' "
	                +"group by a.mcht_cd, a.term_id) c, tbl_mcht_inf e,t_operators f where c.mcht_cd = e.mcht_cd "
	                +"and to_number(e.ext1) = f.id ";
		}
		
		 
		return countSql;
	}

	@Override
	protected String getSearchHQL() {
		
		String sql = "";
		
		if (roleType.equals(Role.O_MANAGER.getCode() )) {
			sql = "select e.mcht_cd,c.term_id,e.name_busi,e.prov_cd,e.city_cd,e.up_mcc_cd,(select i.superparentname "
			           +"from t_mcc_detail i where i.code = e.up_mcc_cd),(select g.org_name from tbl_org_main g "
			           +"where g.org_code = f.oneagentid),(select h.name from tbl_area h where h.id = f.companyid), "
			           +"c.transCount,c.transAmt,c.transFee,c.income,nvl((select x.real_name from tbl_mcht_extend_info q,t_operators x where to_number(q.develop_person)=x.id and q.mcth_cd=e.mcht_cd),f.real_name) "
			           +"from (select a.mcht_cd,a.term_id,sum(a.trans_count) transCount,sum(a.trans_amt) transAmt, "
			           +"sum(a.trans_fee) transFee,sum(a.income) income "
			           +"from t_report_day a,tbl_mer_agent_relation tm where a.mcht_cd=tm.merno and tm.agentid="+agentId+" and  a.trans_dt >= '"+minDate+"' and a.trans_dt <= '"+maxDate+"' "
			           +"group by a.mcht_cd, a.term_id) c, tbl_mcht_inf e,t_operators f where c.mcht_cd = e.mcht_cd "
			           +"and to_number(e.ext1) = f.id ";
		}else{
			sql = "select e.mcht_cd,c.term_id,e.name_busi,e.prov_cd,e.city_cd,e.up_mcc_cd,(select i.superparentname "
			           +"from t_mcc_detail i where i.code = e.up_mcc_cd),(select g.org_name from tbl_org_main g "
			           +"where g.org_code = f.oneagentid),(select h.name from tbl_area h where h.id = f.companyid), "
			           +"c.transCount,c.transAmt,c.transFee,c.income,nvl((select x.real_name from tbl_mcht_extend_info q,t_operators x where to_number(q.develop_person)=x.id and q.mcth_cd=e.mcht_cd),f.real_name) "
			           +"from (select a.mcht_cd,a.term_id,sum(a.trans_count) transCount,sum(a.trans_amt) transAmt, "
			           +"sum(a.trans_fee) transFee,sum(a.income) income "
			           +"from t_report_day a where a.trans_dt >= '"+minDate+"' and a.trans_dt <= '"+maxDate+"' "
			           +"group by a.mcht_cd, a.term_id) c, tbl_mcht_inf e,t_operators f where c.mcht_cd = e.mcht_cd "
			           +"and to_number(e.ext1) = f.id ";
		}
		
				
		return sql;
	}

	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		return "order by e.mcht_cd";
	}

	public String getMerNo() {
		return merNo;
	}

	public void setMerNo(String merNo) {
		this.merNo = merNo;
	}

	public String getMerName() {
		return merName;
	}

	public void setMerName(String merName) {
		this.merName = merName;
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public String getAgentId() {
		return agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	public String getRoleType() {
		return roleType;
	}

	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}
	
}
